<?php

require_once '../include/common.php';
require_once '../mail.php';
require_once '../include/smtp.class.php';
include_once "cpzan_class.php";
function str_post($rows){
	foreach($rows as $k=>$row){
		$data.="$k=".urlencode($row)."&";
	}
	return rtrim($data,'&');
}
function send_active_mail($mail,$do='SID',$qq){
		$post[sendto]=$mail;//收件人邮箱
		$post[title]="秒赞网{$do}过期提醒";//邮件标题
		$post[content]="您好。你在".WEBNAME."[".WEBDOMAIN."]"."添加的QQ:{$qq}的{$do}已经过期，为了不影响你的正常使用，尽快到<a href='http://".$_SERVER['SERVER_NAME']."'>".WEBNAME."</a>更新你的{$do}!更多精彩内容请访问http://www.hnit.gq";//邮件内容
		$post[user]=EMAIL;//邮箱账号
		$post[pwd]=MAILPWD;//邮箱账号密码，QQ邮箱填独立密码
		$post[nick]=WEBNAME;//发送者昵称
		$post[host]=MAILHOST;//邮箱STMP服务器，QQ邮箱不用填写
		$post[port]=MAILPORT;//STMP端口
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL,'../include/smtp.class.php');
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS,str_post($post));
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		$ret = curl_exec($ch);
		curl_close($ch);
		echo $ret;
}
ignore_user_abort();
set_time_limit(0); 
$file = "cache/dz.db";
$hs_num = file_get_contents($file);
$hs= $hs_num + 1;
file_put_contents($file, $hs);
	$dz_sql = "SELECT `qq`,dz,`sid`,`skey`,`id` FROM `w_qq` WHERE dz>0 AND sidzt=0";
	$dz_sth = $db->query($dz_sql);
	$dz=$dz_sth->fetchAll();
	
	foreach ($dz as $value) {
		$zan=new qqzan();
		$zan->set($value[qq],$value['sid'],$value['skey']);
		if($value['dz']==2){
			$zan->getnew(1);
		}else{
			$zan->getnew();
		}
		if($zan->sidzt){
			$db->exec("UPDATE `w_qq` SET sidzt=1,skeyzt=1,dz=0,gq=0,pl=0,shuo=0 where qq='{$value[qq]}'");
			$sql = "SELECT email FROM w_user WHERE id='{$value[id]}'";
			$sth = $db->query($sql);
			$result = $sth->fetch();
			send_active_mail($result['email'],'SID',$value[qq]);
		}
		if($zan->skeyzt){
			$db->exec("UPDATE `w_qq` SET skeyzt=1,dz=1 where qq='{$value[qq]}'");
			$sql = "SELECT email FROM w_user WHERE id='{$value[id]}'";
			$sth = $db->query($sql);
			$result = $sth->fetch();
			send_active_mail($result['email'],'SKEY',$value[qq]);
		}
	}
echo 'ok';
?>